package io.knifer.gokexceltask.controller;

import io.knifer.gokexceltask.exception.InvalidParamException;
import io.knifer.gokexceltask.pojo.domain.ResultInfo;
import io.knifer.gokexceltask.utils.HttpUtils;
import io.knifer.gokexceltask.utils.RIUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionResolver {
    @ExceptionHandler(InvalidParamException.class)
    public ResultInfo<Void> handle(){
        return RIUtils.create(401, "参数不合法", null);
    }

    @ExceptionHandler(Throwable.class)
    public ResultInfo<Void> handle(Throwable e){
        HttpUtils.getResponse().setStatus(500);
        log.error(e.getMessage(), e);

        return RIUtils.create(500, "服务器内部异常", null);
    }
}
